package com.bawei.module_home

import android.view.View
import androidx.lifecycle.ViewModelProvider
import com.bawei.lib_common.mvi.base.BaseMVIActivity
import com.bawei.module_home.databinding.ActivityHomeBinding
import com.bawei.module_home.home.viewmodel.HomeViewModel

class HomeActivity() : BaseMVIActivity() {
    private lateinit var homeViewModel: HomeViewModel
    private lateinit var binding: ActivityHomeBinding

    override fun generateViewModel() {
        homeViewModel = ViewModelProvider(this)[HomeViewModel::class.java]
    }

    override fun getLayoutRootView() : View {
        binding = ActivityHomeBinding.inflate(layoutInflater)
        return binding.root
    }

    override fun handleState() {
        //处理状态
//        lifecycleScope.launch {
//            repeatOnLifecycle(Lifecycle.State.STARTED) {
//                homeViewModel.simpleTypeFlow_.collect {
//                    when (it) {
//                        is SimpleTypeState.Init -> {
//                            showMsg("初始化")
//                        }
//
//                        is SimpleTypeState.Empty -> {
//                            showMsg("空")
//                        }
//
//                        is SimpleTypeState.Failed -> {
//                            showMsg("失败")
//                        }
//
//                        is SimpleTypeState.SimpleTypeSuccess -> {
//                            Log.d("sss----", "${it.list.toString()}")
//                            showMsg("成功")
//                        }
//                    }
//                }
//            }
//        }
    }
    override fun initData() {
        super.initData()
//        //发送意图
//        lifecycleScope.launch {
//            repeatOnLifecycle(Lifecycle.State.STARTED){
//                homeViewModel.intents.send(SimpleTypeIntent.getSimpleType)
//                homeViewModel.handleIntent()
//            }
//
//        }
    }

    override fun initView() {
        super.initView()
        //        showMsg("jie"+6/0)
//        lifecycleScope.launch {
//            repeatOnLifecycle(Lifecycle.State.STARTED){
//                withContext(Dispatchers.IO){
//                    //走mvvm
//                    val videoEntity = TakeVideoEntity(videoLocalPath = "jajaj", userid = 1)
//                    val videoEntity2 = TakeVideoEntity(videoLocalPath = "jajaj22", userid = 2)
////                    DBUtils.getDB().takeVideoDao().insertAll(videoEntity2,videoEntity)
////
////                    DBUtils.getDB().takeVideoDao().getAll().forEach {
////                        Log.d("TAG", "initView: ${it.videoLocalPath}")
////                    }
//                }
//
//            }
//        }
    }

}
